package de.stefanocke.roo.wicket.model;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

import de.stefanocke.roo.wicket.base.ModelClassAwareItdMetadataBase;
import de.stefanocke.roo.wicket.base.ModelClassAwareMetadataCreationParams;

public class BeanPropertiesMetadata extends ModelClassAwareItdMetadataBase<BeanPropertiesAnnotationValues> {
	

	private List<BeanPropertyMetadata> properties;

	public BeanPropertiesMetadata(ModelClassAwareMetadataCreationParams<BeanPropertiesAnnotationValues> cmcp,
			List<BeanPropertyMetadata> properties) {
		super(cmcp, new BeanPropertiesMetadataItdBuilder());
		this.properties = properties;
		buildItdTypeDetails();
	}

	public List<BeanPropertyMetadata> getProperties() {
		return Collections.unmodifiableList(properties);
	}
	
	public List<BeanPropertyMetadata> getProperties(boolean withExcludedFields) {
		List<BeanPropertyMetadata> result = new ArrayList<BeanPropertyMetadata>(properties);
		if (!withExcludedFields) {
			Iterator<BeanPropertyMetadata> iterator = result.iterator();
			while (iterator.hasNext()) {
				if (iterator.next().isExcluded()) {
					iterator.remove();
				}

			}
		}
		return Collections.unmodifiableList(result);
	}
	
	
	

	/**
	 * This metadata is not persisted in an ITD. Instead, it just consists of
	 * propertiesForScaffolding member...
	 * Use its hashcode to determine changes
	 */
	@Override
	public int hashCode() {
		return properties.hashCode();
	}

	@Override
	public String toString() {
		return "BeanPropertiesMetadata [properties=" + properties + "]";
	}
	
	

}
